package server.core.factory;

import server.core.AbstractSend2Data;
import server.core.AbstractSenderFactory;

/**
 * describe:
 *
 * @author helloworldyu
 * @data 2018/1/25
 */
public class SimpleFactory {

	/**
	 *
	 * @param family 协议家族 tcp, udp
	 * @param protocolCode tcp(hgs,common) udp(coap)
	 * @return sender or null
	 */
	public static AbstractSend2Data createSender(String family,String protocolCode) {
		//这里的条件可以是多种多样的
		//负杂的装饰者模式装饰的产品类。
		AbstractSenderFactory factory;
		if (family.equals("UDP")) {
			factory = new CoapSenderFactory();
		} else if (family.equals("TCP")) {
			factory = new TcpSenderFactory();
		} else {
			return null;
		}
		//产品
		AbstractSend2Data sender = factory.createSender(protocolCode);
		return sender;
	}
}